﻿using System;
using System.Drawing;
using System.Web.UI.WebControls;
using SemiCASE.Interfaces;


namespace SemiCASE.UserControls
{
    public partial class MessageBox : System.Web.UI.UserControl, IMessageBox
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                Close();
        }

        public void Close()
        {
            BilgiPanel.Visible = false;
            UyariPanel.Visible = false;
            HataPanel.Visible = false;
            BasariPanel.Visible = false;
            NonePanel.Visible = false;
            tableMsgBox.Visible = false;
            divMsgBox.Style.Add("display", "none");
        }

        Color fColor = Color.Black;
        Color bColor = Color.White;
        bool fBold = false;
        bool fItalic = false;
        FontSize fSize = FontSize.NotSet;
        private void DefineLabelFontStyle(ref Label pLabel)
        {
            pLabel.ForeColor = fColor;
            pLabel.BackColor = bColor;
            pLabel.Font.Bold = fBold;
            pLabel.Font.Italic = fItalic;
            pLabel.Style.Add("Font-Size", fSize.ToString());
        }

        public void Show(string pMesaj, MesajTuruEnum pMesajTuru, bool pTamamButtonVisible
            , string pForeColor, string pBackColor, bool pFontBold, bool pFontItalic, FontSize pFontSize)
        {
            Close();
            if (pMesaj == string.Empty) return;

            if (pForeColor != string.Empty) { if (pForeColor.Substring(0, 1) != "#")pForeColor = "#" + pForeColor; fColor = System.Drawing.ColorTranslator.FromHtml(pForeColor); }
            if (pBackColor != string.Empty) { if (pBackColor.Substring(0, 1) != "#")pBackColor = "#" + pBackColor; bColor = System.Drawing.ColorTranslator.FromHtml(pBackColor); }
            fBold = pFontBold;
            fItalic = pFontItalic;
            fSize = pFontSize;

            switch (pMesajTuru)
            {
                case MesajTuruEnum.Bilgi:
                    BilgiPanel.Visible = true;
                    LabelAciklama.Text = pMesaj;
                    DefineLabelFontStyle(ref LabelAciklama);
                    ButtonAciklamaTamam.Visible = pTamamButtonVisible;
                    break;

                case MesajTuruEnum.Uyari:
                    UyariPanel.Visible = true;
                    LabelUyari.Text = pMesaj;
                    DefineLabelFontStyle(ref LabelUyari);
                    ButtonUyariTamam.Visible = pTamamButtonVisible;
                    break;

                case MesajTuruEnum.Hata:
                    HataPanel.Visible = true;
                    LabelHata.Text = pMesaj;
                    DefineLabelFontStyle(ref LabelHata);
                    ButtonHataTamam.Visible = pTamamButtonVisible;
                    break;

                case MesajTuruEnum.Basari:
                    BasariPanel.Visible = true;
                    LabelBasari.Text = pMesaj;
                    DefineLabelFontStyle(ref LabelBasari);
                    ButtonBasariTamam.Visible = pTamamButtonVisible;
                    break;

                case MesajTuruEnum.Bos:
                    NonePanel.Visible = true;
                    LabelNone.Text = pMesaj;
                    DefineLabelFontStyle(ref LabelNone);
                    ButtonNoneTamam.Visible = pTamamButtonVisible;
                    break;
                default: return;
            }
            tableMsgBox.Visible = true;
            divMsgBox.Style.Add("display", "block");
        }

        public void Show(string pMesaj)
        {
            Show(pMesaj, MesajTuruEnum.Bilgi, true, "", "", false, false, FontSize.NotSet);
        }

        public void Show(string pMesaj, MesajTuruEnum pMesajTuru)
        {
            Show(pMesaj, pMesajTuru, true, "", "", false, false, FontSize.NotSet);
        }

        public void Show(string pMesaj, MesajTuruEnum pMesajTuru, bool pTamamButtonVisible)
        {
            Show(pMesaj, pMesajTuru, pTamamButtonVisible, "", "", false, false, FontSize.NotSet);
        }

    }
}




